do-while


do-while

Another instruction similar to while is do-while. In a do-while block the conditional is check at the end of the block, meaning that the group of instructions is executed at least one. Observe that in the instructions while and for, the conditional is check at the beginning of the block, and it is possible that the group of instructions never gets executed.
Otra instrucción semejante al while es la instrucción do-while. En un bloque do-while la condición es verificada al final de bloque, implicando así que el grupo de instrucciones es ejecutado al menos una vez. Observe que en las instrucciones while y for, la condición es verificada al principio del bloque y que que es posible que el grupo de instrucciones no se ejecute nunca.

Problem 1
What the number does the user has to type to stop the program?
Que número tiene que escribir el usuario para detener el programa?

Program.cpp
int _tmain(int argc, wchar_t* argv[])
{
     int n=10;
     do
     {
          cout<<"Type a number: ";
          cin>>n;
     }
     while (n != 100);
     return 0;
}

Problem 2
Create a Wintempla Dialog application called BrownEyes to test the following code. After creating the project, add a multiline textbox called tbxOutput.
Cree una aplicación de Diálogo de Wintempla llamada BrownEyes para probar el código siguiente. Después de crear el proyecto, agregue una caja de texto de multilínea llamada tbxOutput.

BrowEyes.cpp
void BrowEyes::Window_Open(Win::Event& e)
{
     wchar_t text[64];
     double x = 220.0;
     do
     {
          _snwprintf_s(text, 64, _TRUNCATE, L"%g\r\n", x);
          tbxOutput.Text += text;
          x -= 50.0;
     }
     while(x > 100.0);
}

Problem 3
Create a Wintempla Dialog application called Nico to test the following code. After creating the project, add a multiline textbox called tbxOutput.
Cree una aplicación de Diálogo de Wintempla llamada Nico para probar el código siguiente. Después de crear el proyecto, agregue una caja de texto de multilínea llamada tbxOutput.

Nico.cpp
void Nico::Window_Open(Win::Event& e)
{
     wchar_t text[64];
     double x = 220.0, y = 1;
     do
     {
          y *= 4.0;
          x -= 40.0;
          _snwprintf_s(text, 64, _TRUNCATE, L"%g, %g\r\n", x, y);
          tbxOutput.Text += text;
     }
     while(x > 500.0);
}


Problem 4
Create a Wintempla Dialog application called Luis to test the following code. After creating the project, add a multiline textbox called tbxOutput.
Cree una aplicación de Diálogo de Wintempla llamada Luis para probar el código siguiente. Después de crear el proyecto, agregue una caja de texto de multilínea llamada tbxOutput.

Luis.cpp
void Luis::Window_Open(Win::Event& e)
{
     wchar_t text[64];
     int x = -1000, y = -100;
     do
     {
          _snwprintf_s(text, 64, _TRUNCATE, L"%d, %d\r\n", x, y);
          tbxOutput.Text += text;
          y += 5;
          x += 400;
     }
     while(x < 50.0 || y <-90);
}


© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home